//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.user;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.live.base.domain.User;
import com.ruoyi.live.tool.commons.ICommons;
import com.ruoyi.live.tool.utils.Message;
import com.ruoyi.live.user.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

@Controller("oldUserController")
@RequestMapping({"/user"})
public class UserController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(UserController.class);
    @Autowired
    UserService service;

    public UserController() {
    }

    @RequestMapping({"/UserController/index"})
    public String index() {
        return "/user/user_list";
    }

    @ResponseBody
    @RequestMapping({"/UserController/query"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public TableDataInfo query(User entity) throws Exception {
        this.startPage();
        List<User> list = this.service.query(entity);
        return this.getDataTable(list);
    }

    @ResponseBody
    @RequestMapping({"/UserController/add"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public Message add(User entity) {
        try {
            this.service.addUser(entity);
            return new Message(true, "新增成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, var3.getMessage());
        }
    }

    @ResponseBody
    @RequestMapping({"/UserController/update"})
    public Message update(User entity) {
        try {
            this.service.updateUser(entity);
            return new Message(true, "修改成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @ResponseBody
    @RequestMapping({"/UserController/lock"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public Message lock(String id) {
        try {
            this.service.deleteUser(id.split(","), 2);
            return new Message(true, "锁定成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @ResponseBody
    @RequestMapping({"/UserController/rePass"})
    public Message rePass(String id) {
        try {
            this.service.doRePass(id.split(","));
            return new Message(true, "重置成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @ResponseBody
    @RequestMapping({"/UserController/unlock"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public Message unlock(String id) {
        try {
            this.service.deleteUser(id.split(","), 1);
            return new Message(true, "解锁成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, var3.getMessage());
        }
    }

    @RequestMapping({"/UserController/view"})
    public ModelAndView view(Long id, String page) {
        ModelAndView mv = new ModelAndView("user/" + page);
        if (id != null) {
            try {
                mv.addObject("entity", this.service.getUser(id));
            } catch (Exception var5) {
                return (new ModelAndView("error")).addObject("tip", var5.getMessage());
            }
        }

        return mv;
    }

    @ResponseBody
    @RequestMapping({"/UserController/insertBatchUser"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public Message insertBatchUser(String start, Integer noStart, Integer noStop, Long classId, Integer userDuty) {
        return new Message(true, this.service.insertBatchUser(start, noStart, noStop, classId, userDuty));
    }

    @ResponseBody
    @RequestMapping({"/UserController/initSystem"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message initSystem(String password, Integer type, HttpServletRequest request, HttpServletResponse response) {
        if (type != null && password != null) {
            try {
                this.service.initSystem(password, type, request, response);
                return new Message(true, "");
            } catch (Exception var6) {
                var6.printStackTrace();
                return new Message(false, "");
            }
        } else {
            return new Message(false, "");
        }
    }

    @RequestMapping({"/ShiroUserController/updatePsd"})
    public ModelAndView updatePsd() {
        return new ModelAndView("/platform/update_psd");
    }

    @ResponseBody
    @RequestMapping({"/ShiroUserController/updatePsdSave"})
    public Message updatePsdSave(String userpass, String userpassnew) {
        if (!ICommons.isNullOrEmpty(userpass) && !ICommons.isNullOrEmpty(userpassnew)) {
            try {
                return this.service.updatePsdSave(userpass, userpassnew);
            } catch (Exception var4) {
                var4.printStackTrace();
                return new Message(false, "修改失败");
            }
        } else {
            return new Message(false, "输入有误");
        }
    }
}
